home *** CD-ROM | disk | FTP | other *** search
/ Programming a Multiplayer FPS in DirectX / Programming a Multiplayer FPS in DirectX (Companion CD).iso / DirectX / dxsdk_oct2004.exe / dxsdk.exe / Documentation / DirectX9 / directx9_m.chm / directx / code / pvutil.js < prev    next >
Encoding:
Text File  |  2004-09-30  |  6.5 KB  |  304 lines

  1. <![CDATA[
  2.  
  3. // BUGBUG: Need to create CPVResults/CCVResults to store lookup data and CPV/CCV to encapsulate Lookup
  4. // BUGBUG: Rather than accessing global goLookup, pass this into the CPV and CCV constructor
  5.  
  6. // Encapsulation of possible value results data
  7. function CPVData()
  8. {
  9. //    this.Init();
  10. }
  11.  
  12. CPVData.prototype.Init = function()
  13. {
  14.     this.caption = "";
  15.     this.devlang = "";
  16.     this.error = "";
  17.     this.className = "";
  18.     this.pid = "";
  19.     this.rid = "";
  20. }
  21.  
  22. function CCVData()
  23. {
  24. //    this.Init();
  25. }
  26.  
  27. CCVData.prototype.Init = function()
  28. {
  29.     this.caption = "";
  30.     this.devlang = "";
  31.     this.error = "";
  32.     this.cvid = "";
  33.     this.rid = "";
  34. }
  35.  
  36. // Lookup the composite value associated with the xref
  37. function LookupCV(oSrc, oData, sCurLang)
  38. {    
  39.     oData.Init();
  40.     
  41.     var sCVID = oData.caption = oSrc.getAttribute("cvid");
  42.     if (!sCVID)
  43.     {
  44.         oData.error = "expected cvid was not specified.";
  45.         return false;
  46.     }
  47.  
  48.     var sRID = oData.rid = oSrc.getAttribute("rid");
  49.     if (!IsSelfReference(sRID))
  50.     {        
  51.         if (!goLookup.RetrieveTarget(sRID))
  52.         {
  53.             oData.error = "unable to find rid '" + sRID + "' among targets.";
  54.             return false;
  55.         }
  56.     }
  57.     else
  58.     {
  59.         var oNode = ownerDocument.selectSingleNode("/inetsdk:topic/content/params/param[@get]/pv[@type='composite']/cv[@name='" + sCVID + "']");
  60.         if (!oNode)
  61.         {
  62.             oData.error = "cvid '" + sCVID + "' not found.";
  63.             return false;
  64.         }
  65.     }
  66.  
  67.     return true;
  68. }
  69.  
  70. function GetCVCaption(oSrc, oData)
  71. {
  72.     return oData.caption;
  73. }
  74.  
  75. // Lookup the possible value associated with the specified xref
  76. function LookupPV(oSrc, oData, sCurLang)
  77. {
  78.     oData.Init();
  79.     
  80.     var sDevLang = oSrc.getAttribute("devlang"); // author can override the devlang (or specify it in a lang-neutral topic)
  81.     if (!sDevLang)
  82.     {
  83.         sDevLang = sCurLang;
  84.     }
  85.     oData.devlang = sDevLang; // the devlang as defined by the current template
  86.  
  87.     var sPV = oData.caption = oSrc.getAttribute("pvid");
  88.     // the following should never happen
  89.     if (!sPV)
  90.     {
  91.         oData.error = "expected pvid was not specified.";
  92.         return false;
  93.     }
  94.  
  95.     // BUGBUG: Should first determine if the xref is to a doc of type method, function, struct, or enum
  96.     // BUGBUG: Use that info to get the appropriate attribute (@pid, @mid, @cid)
  97.     var sRID = oData.rid = oSrc.getAttribute("rid");    
  98.     var bSelfRef = IsSelfReference(sRID);
  99.     var sType;
  100.  
  101.     var sPVType = oSrc.getAttribute("pvtype");
  102.  
  103.     if (bSelfRef)
  104.     {
  105.         sType = ownerDocument.selectSingleNode("/inetsdk:topic/metadata/@type").value;        
  106.     }
  107.     else
  108.     {
  109.         if (!sPVType)
  110.         {
  111.             oData.error = "specify pvtype=(range|literal|flag) when pv reference points to remote topic";
  112.             return false;
  113.         }
  114.  
  115.         var oTarget;
  116.         if (!(oTarget = goLookup.RetrieveTarget(sRID)))
  117.         {
  118.             oData.error = "unable to find rid '" + sRID + "' among targets.";
  119.             return false;
  120.         }
  121.         else
  122.         {
  123.             sType = oTarget.getAttribute("type");
  124.         }
  125.     }
  126.  
  127.     var sQuery = "/inetsdk:topic/content/";
  128.     var sMID;
  129.     switch(sType)
  130.     {
  131.     case 'struct':
  132.         sMID = oData.mid = oSrc.getAttribute("mid");
  133.         if (!sMID)
  134.         {
  135.             oData.error = "expected @mid not found.";
  136.             return false;
  137.         }
  138.         sQuery += "members/member[@name='" + sMID + "'][pv]";
  139.         break;
  140.     case 'property':
  141.     case 'method':
  142.     case 'function':
  143.     case 'winmsg':
  144.         sMID = oData.pid = oSrc.getAttribute("pid");
  145.         if (!sMID)
  146.         {
  147.             oData.error = "expected @pid not found.";
  148.             return false;
  149.         }
  150.         sQuery += "params/param[@name='" + sMID + "'][pv]";
  151.         break;
  152.     case 'isv_element':
  153.         sMID = oData.aid = oSrc.getAttribute("aid");
  154.         if( !sMID )
  155.         {
  156.             oData.error = "expected @aid not found.";
  157.             return false;
  158.         }
  159.         sQuery += "attribs/attrib[@name='" + sMID + "'][pv]";
  160.         break;
  161.     case 'htmldeclaration':
  162.         sMID = oData.aid = oSrc.getAttribute("aid");
  163.         if( !sMID )
  164.         {
  165.             oData.error = "expected @aid not found.";
  166.             return false;
  167.         }
  168.         sQuery += "attribs/attrib[@name='" + sMID + "'][pv]";
  169.         break;
  170.     default:
  171.         oData.error = "type '" + sType + "' not supported.";
  172.         return false;
  173.     }
  174.         
  175.  
  176.     if (bSelfRef)
  177.     {
  178.         // find the pv among the params/members in the current topic
  179.         var oMember = ownerDocument.selectSingleNode(sQuery);
  180.         if (!oMember)
  181.         {
  182.             oData.error = "param/member '" + sMID + "' not found in current topic.";
  183.             return false;        
  184.         }
  185.  
  186.         // lookup name preferentially
  187.         var oPV;
  188.         if (oPV = oMember.selectSingleNode("pv[@name='" + sPV + "']"))
  189.         {        
  190.             if (sDevLang == 'scr')
  191.             {
  192.                 var sValue = oPV.getAttribute('value');
  193.                 if (!sValue)
  194.                 {
  195.                     oDest.error = "unable to retrieve value from name '" + sPV + "'.";
  196.                     return false;
  197.                 }
  198.  
  199.                 sPV = oData.caption = sValue;            
  200.             }
  201.         }
  202.         else if (oPV = oMember.selectSingleNode("pv[@value='" + sPV + "']"))
  203.         {
  204.             // BUGBUG: Disallow this in the C++ case? It's what scripters want but probably not what C++ programmers want.
  205.         }
  206.         else if (oPV = oMember.selectSingleNode("pv[@rid='" + sPV + "']"))
  207.         {
  208.             var oFlag = ownerDocument.selectSingleNode("/inetsdk:topic/flags/flag[@id='" + sPV + "']");
  209.             if (!oFlag)
  210.             {
  211.                 oData.error = "flag with id '" + sPV + "' not found.";
  212.                 return false;
  213.             }
  214.  
  215.             var sAttr = aFlagAttrMap[sDevLang];
  216.             if (!sAttr)
  217.             {
  218.                 oDest.error = "devlang '" + sDevLang + "' not found in flag map.";
  219.                 return false;
  220.             }
  221.             
  222.             var sCaption = oFlag.getAttribute(sAttr);
  223.             if (!sCaption)
  224.             {
  225.                 oData.error = "flag with id '" + sPV + "' missing '" + sAttr + "' attribute.";
  226.                 return false;
  227.             }
  228.             else
  229.             {
  230.                 sPV = oData.caption = sCaption;
  231.             }
  232.         }
  233.         else
  234.         {
  235.             oData.error = "pv '" + sPV + "' not found.";
  236.             return false;
  237.         }
  238.     }
  239.  
  240.     if (!sPVType && oPV)
  241.     {
  242.         sPVType = oPV.getAttribute("type");
  243.     }
  244.     
  245.     if (!MapPVTypeToCSSClass(sPVType, oData, sDevLang))
  246.     {
  247.         return false;
  248.     }
  249.     
  250.     return true;
  251. }
  252.  
  253. // given a pv/@type of an xref/@pvtype, map to a CSS class for presentation
  254. function MapPVTypeToCSSClass(sPVType, oData, sDevLang)
  255. {
  256.     if (!sPVType)
  257.     {
  258.         return false;
  259.     }
  260.     
  261.     switch(sPVType)
  262.     {
  263.         case 'range':
  264.             oData.className = 'clsRange';
  265.             break;
  266.         case 'literal':
  267.             oData.className = 'clsLiteral';
  268.             break;
  269.         case 'flag':
  270.             if (sDevLang == 'scr')
  271.             {
  272.                 oData.className = 'clsLiteral';
  273.             }
  274.             else
  275.             {
  276.                 oData.className = 'clsFlag';
  277.             }
  278.             
  279.             break;
  280.         otherwise:
  281.             oData.error = "unsupported pvtype '" + sType + "'. Use (range|literal|flag)."
  282.             return false;
  283.     }
  284.     
  285.     return true;
  286. }
  287.  
  288. function GetPVCaption(oSrc, oData)
  289. {
  290.     return oData.caption;
  291. }
  292.  
  293. function GetPVClass(oSrc, oData)
  294. {
  295.     return oData.className;
  296. }
  297.  
  298. function GetLastError(o)
  299. {
  300.     return (o && o.error ? o.error : "unexpected error");
  301. }
  302.  
  303. ]]>
  304.